package com.example.demoannotation.service;

import com.example.demoannotation.bean.LoginUserBean;
import org.springframework.stereotype.Component;

/**
 *持有用户信息，用于代替session对象
 */
@Component
public class HostHolder {

    //ThreadLocal本质是以线程为key存储元素
    private ThreadLocal<LoginUserBean> coupUserBeans = new ThreadLocal<>();

    public void setUser(LoginUserBean user){
        coupUserBeans.set(user);
    }

    public LoginUserBean getUser(){
        return coupUserBeans.get();
    }

    public void clear(){
        coupUserBeans.remove();
    }
}
